package com.findyou.controller;

import com.findyou.pojo.Translation;
import com.findyou.result.Result;
import com.findyou.service.TranslationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Title: TranslationController
 * @Author 贾金博
 * @Package com.findyou.controller
 * @Date 2025/6/8 下午6:55
 * @description: 控制类
 */

@RestController
@RequestMapping("/translation")
public class TranslationController {

    @Autowired
    private TranslationService translationService;

    /**
     * 根据用户信息查找用户的翻译历史记录
     * @param userId
     * @return
     */
    @GetMapping("/findByUserId")
    public Result getTranslationsByUserId(int userId) {
        return Result.success("查找成功", translationService.findAllByUserId(userId));
    }

    /**
     * 向数据库插入翻译
     * @param translation
     * @return
     */
    @GetMapping("/insert")
    public Result insertTranslation(int userId, String want, String translation, String date) {
        Translation t = new Translation();
        t.setUserId(userId);
        t.setWant(want);
        t.setTranslation(translation);
        t.setDate(date);
        return Result.success("插入翻译成功",translationService.insertTranslation(t));
    }


}
